from openpyxl import load_workbook



class MyExcel:

    def __init__(self, excel_path, sheet_name):
        # 1.加载一个excel，得到工作簿
        wb = load_workbook(excel_path)
        # 选择一个表单-通过表单名
        self.sh = wb[sheet_name]

    def read_data(self):
        # 存储表单下读取到的所有数据-每一个成员都是一个字典
        all_data = []
        data = list(self.sh.values)
        keys = data[0]  # 获取所有的列
        for row in data[1:]:
            row_dict = dict(zip(keys, row))
            all_data.append(row_dict)
        return all_data


if __name__ == '__main__':
    execl_path = r"C:\Users\Mr MING\PycharmProjects\自动化测试\learn-git\yunyantest_Interface\day5\testdatas\测试用例.xlsx"
    me = MyExcel(execl_path, "登录")
    cases = me.read_data()
    for case in cases:
        print(case)